package cn.com.thingo.hyintelligent.util;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumberVerifiedUtils {
    /**
     * 车牌号验证
     */
    public static boolean isCarNumber(String carNum) {
        String carNumRegex = "^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-Z_0-9]{4}[A-Z_0-9挂学警港澳]$";
        return !TextUtils.isEmpty(carNum) && carNum.matches(carNumRegex);
    }

    /**
     * 身份证号码验证
     */
    public static boolean isIdCard(String idCard) {
        String idCardRegex15 = "^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}$";
        String idCardRegex18 = "^[1-9]\\d{5}(18|19|20|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
        return !TextUtils.isEmpty(idCard) && (idCard.matches(idCardRegex15) || idCard.matches(idCardRegex18));
    }

    /**
     * 电话号码验证
     */
    public static boolean isTelephone(String telephone) {
        String mobileRegex = "^((13[0-9])|(15[^4])|(166)|(17[0-8])|(18[0-9])|(19[8-9])|(147,145))\\d{8}$";
        String telephoneRegex = "^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$";
        return !TextUtils.isEmpty(telephone) && (telephone.matches(mobileRegex) || telephone.matches(telephoneRegex));
    }

    /**
     * 判断手机号码
     */
    private static boolean isChinaPhoneLegal(String number) {
        String regExp = "^((13[0-9])|(15[^4])|(166)|(17[0-8])|(18[0-9])|(19[8-9])|(147,145))\\d{8}$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(number);
        return m.matches();
    }

}
